package dd.view;

import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

import dd.control.SetChoiceButtonController;
import dd.model.Event;
import dd.model.Model;

import javax.swing.JTextPane;

public class addChoiceScreen extends JFrame {
	
	
	private JPanel contentPane;
	private JTextField enterChoiceTextField;
	JLabel eventNameJLable;
	Event event;
	JButton setChoiceButton;
	JTextPane textPane = new JTextPane();
	String allchoice = null;
	boolean oncepress = false;
	/**
	 * Launch the application.
	 */
	
	
	/**
	 * Create the frame.
	 */
	public addChoiceScreen(Event event) {
		this.event = event;
		Model model = Model.getInstance();
		//event = model.getEvent();
		 
		//name = event.getEventName();
		//System.out.println(name);
		setTitle("Set Your Choice");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 539, 324);
		contentPane = new JPanel(); 
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
	
		
		System.out.println("Number of choices in set choice form: " + this.event.getNumberLines() + "");
		
		eventNameJLable = new JLabel("Event Name");		
		eventNameJLable.setFont(new Font("Tahoma", Font.PLAIN, 15));
		eventNameJLable.setHorizontalAlignment(SwingConstants.CENTER);
		eventNameJLable.setText(this.event.getEventName());
		eventNameJLable.setBounds(31, 6, 277, 32);
		contentPane.add(eventNameJLable);
		
		JLabel lblOpenModePlease = new JLabel("Open mode Please enter your choicel");
		lblOpenModePlease.setHorizontalAlignment(SwingConstants.CENTER);
		lblOpenModePlease.setBounds(101, 37, 316, 32);
		contentPane.add(lblOpenModePlease);
		//see if this button once pressed
		
		setChoiceButton = new JButton("Set Choice");
		setChoiceButton.setBounds(346, 217, 115, 23);
		contentPane.add(setChoiceButton);
		setChoiceButton.addActionListener(new SetChoiceButtonController(this, this.event));
		
		enterChoiceTextField = new JTextField();
		enterChoiceTextField.setText("");
		enterChoiceTextField.setBounds(101, 216, 175, 21);
		contentPane.add(enterChoiceTextField);
		enterChoiceTextField.setColumns(10);
		
		JLabel lblEventId = new JLabel("Event ID: " + this.event.getEventID());
		lblEventId.setBounds(273, 7, 178, 31);
		contentPane.add(lblEventId);
		
		JLabel lblOther = new JLabel("other choice");
		lblOther.setBounds(12, 81, 78, 40);
		contentPane.add(lblOther);
		
		allchoice = this.event.getChoice(0);
		for(int i = 1;i<this.event.getNumberLines();i++){
			allchoice = allchoice+"\n" + this.event.getChoice(i);
		}
		
		textPane.setBounds(187, 81, 161, 82);
		textPane.setText(allchoice);
		contentPane.add(textPane);
		model.setaddChoiceScreen(this);

	
		
	}
	public JTextField getChoiceTextField() {
		return enterChoiceTextField;
	}
	

	
	public void deletebutton(){
		setChoiceButton.setVisible(false);
		contentPane.updateUI();
	}
	public void setallchoice(){
		allchoice = event.getChoice(0);
		for(int i=1;i<event.getNumberLines();i++){
			allchoice = allchoice+"\n" +event.getChoice(i);
		}
		textPane.setBounds(187, 81, 161, 82);
		textPane.setText(allchoice);
		//contentPane.add(textPane);
		contentPane.updateUI();
	}
}
